package org.jon.web.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import org.jon.domain.User;
import org.jon.service.UserService;

/**
 * Created by administrator on 2017/8/20.
 */
public class UserAction extends ActionSupport implements ModelDriven<User>{
    private User user = new User();
    private UserService userService;

    public String login() throws Exception {
        // 1.调用Service执行登录逻辑
        User loginUser = userService.getUserByCodePassword(user);
        // 2.将返回的User对象放入 session 域中
        ActionContext.getContext().getSession().put("user", loginUser);
        // 3.重定向到项目首页
        return "toHome";
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    @Override
    public User getModel() {
        return user;
    }
}
